package com.bupt.liutong.admin.groupon.form;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;

import com.bupt.liutong.admin.core.base.BaseForm;
import com.bupt.liutong.util.StringUtils;

public class GrouponForm extends BaseForm {

	private static final long serialVersionUID = 6172698546773833353L;
	private Integer websiteId;
	private Integer cityId;
	private String title;
	private String titleDisp;
	private String link;
	private String smallImageUrl;
	private String mediumImageUrl;
	private String largeImageUrl;
	private Double value;
	private String valueDisp;
	private Double price;
	private String priceDisp;
	private Double rebate;
	private String rebateDisp;
	private Double saved;
	private String savedDisp;
	private Integer bought;
	private Date startTime;
	private Date endTime;
	private Date deadline;
	/**
	 * 团购信息获取时间（同一批获取的信息，时间完全相同）
	 */
	private Date createTime;

	public Integer getWebsiteId() {
		return websiteId;
	}

	public void setWebsiteId(Integer websiteId) {
		this.websiteId = websiteId;
	}

	public Integer getCityId() {
		return cityId;
	}

	public void setCityId(Integer cityId) {
		this.cityId = cityId;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
		this.setTitleDisp(title);
	}

	public String getLink() {
		return link;
	}

	public void setLink(String link) {
		this.link = link;
	}

	public String getSmallImageUrl() {
		return smallImageUrl;
	}

	public void setSmallImageUrl(String smallImageUrl) {
		this.smallImageUrl = smallImageUrl;
	}

	public String getMediumImageUrl() {
		return mediumImageUrl;
	}

	public void setMediumImageUrl(String mediumImageUrl) {
		this.mediumImageUrl = mediumImageUrl;
	}

	public String getLargeImageUrl() {
		return largeImageUrl;
	}

	public void setLargeImageUrl(String largeImageUrl) {
		this.largeImageUrl = largeImageUrl;
	}

	public Double getValue() {
		return value;
	}

	public void setValue(Double value) {
		this.value = value;
		this.setValueDisp(value);
		this.setSaved(value, price);
	}

	public Double getPrice() {
		return price;
	}

	public void setPrice(Double price) {
		this.price = price;
		this.setPriceDisp(price);
		this.setSaved(value, price);
	}

	public Double getRebate() {
		return rebate;
	}

	public void setRebate(Double rebate) {
		this.rebate = rebate;
		this.setRebateDisp(rebate);
	}

	public Integer getBought() {
		return bought;
	}

	public void setBought(Integer bought) {
		this.bought = bought;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public Date getDeadline() {
		return deadline;
	}

	public void setDeadline(Date deadline) {
		this.deadline = deadline;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public String getTitleDisp() {
		return titleDisp;
	}

	public void setTitleDisp(String title) {
		if (!StringUtils.isEmpty(title) && title.length() > 18) {
			this.titleDisp = title.substring(0, 18) + "...";
		} else 
			this.titleDisp = title;
	}

	public String getValueDisp() {
		return valueDisp;
	}

	public void setValueDisp(Double value) {
		if (value == null)
			this.valueDisp = "-";
		else {
			BigDecimal d = new BigDecimal(value.toString());
			d.setScale(2, BigDecimal.ROUND_HALF_UP);
			this.valueDisp = d.stripTrailingZeros().toString();
		}
	}

	public String getPriceDisp() {
		return priceDisp;
	}

	public void setPriceDisp(Double price) {
		if (price == null)
			this.priceDisp = "-";
		else {
			BigDecimal d = new BigDecimal(price.toString());
			d.setScale(2, BigDecimal.ROUND_HALF_UP);
			this.priceDisp = d.stripTrailingZeros().toString();
		}
	}

	public String getRebateDisp() {
		return rebateDisp;
	}

	public void setRebateDisp(Double rebate) {
		if (rebate == null)
			this.rebateDisp = "-";
		else
			this.rebateDisp = rebate.toString();
	}

	public String getSaveDisp() {
		if (value == null || price == null)
			return "-";
		else
			return Double.toString((value - price));
	}

	public Double getSaved() {
		return saved;
	}

	public void setSaved(Double value, Double price) {
		if (value != null && price != null) {
			saved = value - price;
			BigDecimal d = new BigDecimal(saved.toString());
			d.setScale(2, BigDecimal.ROUND_HALF_UP);
			savedDisp = d.stripTrailingZeros().toString();
		}
	}

	public String getSavedDisp() {
		return savedDisp;
	}
}
